var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

var publicPath = 'http://localhost:3000/'; // 确保图片地址引用有效。
var hotMiddlewareScript = 'webpack-hot-middleware/client?reload=true';  //reload = true 参数，如果碰到不能hot reload的情况，就整页刷新。

var config = {
    entry: ['./routers', hotMiddlewareScript],

    output: {
        path: path.resolve(__dirname, 'public'),
        filename: 'index.js',
        publicPath: publicPath
    },
    devtool: 'source-map',

    // devServer: {
    //     inline: true,
    //     port: 3000
    // },

    module: {
        loaders: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',

            query: {
                presets: ['es2015', 'react', 'stage-0']
            }
        },
        {
            test: /\.css$/,
            loader: 'style-loader!css-loader' //ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
        },
        {
            test: /\.(png|jpg|ttf)$/,
            loader: 'url-loader?name=images/[name].[ext]'
        }
        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),   // webpack-dev-middleware & webpack-hot-middleware 插件配置
        new webpack.NoEmitOnErrorsPlugin(),
        new ExtractTextPlugin("[name].css") // 单独为页面引入css
    ]
}

/** javascript related to entry will hot reload */
if (module.hot) {
    module.hot.accept();
}

module.exports = config;